﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Farigola.Engine.SystemData.Entity.inst;

namespace Farigola.Engine.SystemData.Entity.Type
{
    /// <summary>
    /// The base of all entities class hierarchy, types and instances.
    /// </summary>
    public abstract class EntityBase
    {
        //=====================================================================
        #region  Data members.

        /// <summary>
        /// an entity is a system or a user entity, build by the system (and hidden to the user)
        /// or build by the user.
        /// </summary>
        protected EntityDef.TypeSystOrUser _systOrUser = EntityDef.TypeSystOrUser.User;

        /// <summary>
        /// the id of the entity.
        /// </summary>
        protected EntityId _id;

        /// <summary>
        /// the name of the entity.
        /// </summary>
        protected String _name = "";

        /// <summary>
        /// the folder parent containing this entity.
        /// if null, its the root folder of the project.
        /// </summary>
        //protected EntInstFolder _folderParent;

        #endregion

        //=====================================================================
        #region Constructors.

        //---------------------------------------------------------------------
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="systOrUser"></param>
        /// <param name="id"></param>
        /// <param name="name"></param>
        public EntityBase(EntityDef.TypeSystOrUser systOrUser, EntityId id, String name)
        {
            _systOrUser = systOrUser;
            _id = id;
            _name = name;
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        public EntityBase(EntityId id, String name)
        {
            _id = id;
            _name = name;
        }

        #endregion


        //=====================================================================
        #region get/set methods.

        //---------------------------------------------------------------------
        public EntityDef.TypeSystOrUser GetTypeSystOrUser()
        {
            return _systOrUser;
        }

        //---------------------------------------------------------------------
        public void SetId(EntityId id)
        {
            _id = id;
        }

        //---------------------------------------------------------------------
        public EntityId GetId()
        {
            return _id;
        }

        public String GetName()
        {
            return _name;
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// return the folder parent (means the place in the tree) or null 
        ///for this entity.
        /// </summary>
        /// <returns></returns>
        //public EntInstFolder GetParentFolder()
        //{
        //    return _folderParent;
        //}

        //---------------------------------------------------------------------
        /// <summary>
        /// set the folder parent to this entity.
        /// </summary>
        /// <param name="parent"></param>
        //public void SetParentFolder(EntInstFolder parent)
        //{
        //    _folderParent = parent;
        //}

        #endregion

        //=====================================================================
        #region Is methods.

        //---------------------------------------------------------------------
        /// <summary>
        /// Return true if the provided name is equals to the inner name.
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public bool IsNameEquals(String n)
        {
            if (n == null)
                return false;
            if (n.Equals(_name,StringComparison.OrdinalIgnoreCase))
                return true;

            return false;
        }

        #endregion


        //=====================================================================
        #region Others methods.

        //---------------------------------------------------------------------
        public override string ToString()
        {
            return _name;
        }

        #endregion
    }
}
